package tree;

import domin.Student;

public class TreeTest {
    public static void main(String[] args) {
        testAVLTree();
    }

    public static void testMyBinaryTree(){
        MyBinaryTree<String,Student> tree = new MyBinaryTree<>();
        tree.add("5",new Student("5",20,"宋江"));
        tree.add("4",new Student("4",28,"吴用"));
        tree.add("8",new Student("8",26,"林冲"));
        tree.add("1",new Student("1",29,"武松"));
        tree.add("9",new Student("9",60,"鲁智深"));
        tree.add("6",new Student("6",40,"李逵"));
        tree.preOrderPrint();
        Student s1 = tree.search("4");
        Student s2 = tree.search("8");
        Student s3 = tree.search("1");
        Student s4 = tree.search("9");
        System.out.println(s1);
        System.out.println(s2);
        System.out.println(s3);
        System.out.println(s4);
    }

    public static void testThreadsBinaryTree(){
        ThreadsBinaryTree<String,Student> tree = new ThreadsBinaryTree<>();
        tree.add("5",new Student("5",20,"宋江"));
        tree.add("4",new Student("4",28,"吴用"));
        tree.add("8",new Student("8",26,"林冲"));
        tree.add("1",new Student("1",29,"武松"));
        tree.add("9",new Student("9",60,"鲁智深"));
        tree.add("6",new Student("6",40,"李逵"));
        tree.postOrderPrint();
        tree.postOrderThreads();
        System.out.println("===================================");
        tree.postOrderThreadPrints();
    }
    public static void testBinarySortTree(){
        /*       */
        BinarySortTree<Integer,Student> tree = new BinarySortTree<>();
        tree.add(7,new Student("7",20,"宋江"));
/*        tree.add(4,new Student("4",28,"吴用"));
        tree.add(1,new Student("1",26,"林冲"));
        tree.add(5,new Student("5",29,"武松"));
        tree.add(10,new Student("10",60,"鲁智深"));
        tree.add(8,new Student("8",40,"杨志"));
        tree.add(28,new Student("28",40,"公孙胜"));
        tree.add(14,new Student("14",40,"公孙胜1"));
        tree.add(35,new Student("35",40,"公孙胜2"));
        tree.add(13,new Student("13",40,"公孙胜3"));
        tree.add(20,new Student("20",40,"公孙胜4"));
        tree.add(30,new Student("30",40,"公孙胜5"));
        tree.add(37,new Student("37",40,"公孙胜6"));*/
        tree.preOrderPrint();
/*        tree.delete(28);
        System.out.println("==================delete 28==================");
        tree.preOrderPrint();
        tree.delete(35);
        System.out.println("==================delete 35==================");
        tree.preOrderPrint();
        tree.delete(20);
        System.out.println("==================delete 30==================");
        tree.preOrderPrint();*/
        tree.delete(7);
        System.out.println("==================delete 7==================");
        tree.preOrderPrint();
        //System.out.println("=========================================");
        //tree.add(7,new Student("7",35,"大宋江"));
        //tree.preOrderPrint();
/*        tree.delete(1);
        System.out.println("==================delete 1==================");
        tree.preOrderPrint();
        tree.delete(4);
        System.out.println("==================delete 4================");
        tree.preOrderPrint();
        tree.delete(10);
        System.out.println("==================delete 10================");
        tree.preOrderPrint();*/
    }
    public static void testAVLTree(){
        AVLTree<Integer,Student> tree = new AVLTree<>();
        tree.add(7,new Student("7",20,"宋江"));
        tree.add(4,new Student("4",28,"吴用"));
        tree.add(1,new Student("1",26,"林冲"));
        tree.add(5,new Student("5",29,"武松"));
        tree.add(10,new Student("10",60,"鲁智深"));
        tree.add(8,new Student("8",40,"杨志"));
        tree.add(28,new Student("28",40,"公孙胜"));
        tree.add(14,new Student("14",40,"公孙胜1"));
        tree.add(35,new Student("35",40,"公孙胜2"));
        tree.add(13,new Student("13",40,"公孙胜3"));
        tree.add(20,new Student("20",40,"公孙胜4"));
        tree.add(30,new Student("30",40,"公孙胜5"));
        tree.add(37,new Student("37",40,"公孙胜6"));
/*        tree.add(5,null);
        tree.add(3,null);
        tree.add(7,null);
        tree.add(2,null);
        tree.add(4,null);
        tree.add(1,null);*/
        tree.preOrderPrint();
        System.out.println(tree.getTreeHeight());
    }
}
